"""
 当然可以。Selenium 4.x 版本在Python中的用法有一些更新，以下是一些基本的用法示例：

1. **安装Selenium**：
   ```bash
   pip install selenium
   ```

2. **导入WebDriver**：
   ```python
   from selenium import webdriver
   ```

3. **初始化WebDriver**：
   ```python
   # 对于Chrome浏览器
   driver = webdriver.Chrome(executable_path='path/to/chromedriver')

   # 对于Firefox浏览器
   driver = webdriver.Firefox(executable_path='path/to/geckodriver')

   # 对于Edge浏览器
   driver = webdriver.Edge(executable_path='path/to/msedgedriver')
   ```

4. **导航到网页**：
   ```python
   driver.get('https://www.example.com')
   ```

5. **元素定位**：
   ```python
   # 使用By类进行定位
   element = driver.find_element(By.ID, 'element_id')
   element = driver.find_element(By.NAME, 'element_name')
   element = driver.find_element(By.XPATH, "//input[@name='username']")
   element = driver.find_element(By.LINK_TEXT, "Link Text")
   element = driver.find_element(By.PARTIAL_LINK_TEXT, "Partial Link Text")
   element = driver.find_element(By.TAG_NAME, "input")
   element = driver.find_element(By.CLASS_NAME, "class_name")
   element = driver.find_element(By.CSS_SELECTOR, "css_selector")
   ```

6. **操作元素**：
   ```python
   element.send_keys("Text to input")  # 输入文本
   element.click()  # 点击元素
   ```

7. **等待元素**：
   ```python
   from selenium.webdriver.support.ui import WebDriverWait
   from selenium.webdriver.support import expected_conditions as EC

   wait = WebDriverWait(driver, 10)
   element = wait.until(EC.visibility_of_element_located((By.ID, 'element_id')))
   ```

8. **执行JavaScript**：
   ```python
   driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
   ```

9. **处理Cookie**：
   ```python
   driver.add_cookie({'name': 'cookie_name', 'value': 'cookie_value'})
   cookie = driver.get_cookie('cookie_name')
   driver.delete_cookie('cookie_name')
   ```

10. **处理窗口和框架**：
    ```python
    driver.switch_to.window("window_name")
    driver.switch_to.frame("frame_name_or_reference")
    driver.switch_to.default_content()
    ```

11. **截图**：
    ```python
    driver.save_screenshot('screenshot.png')
    ```

12. **关闭浏览器**：
    ```python
    driver.quit()
    ```
"""

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

# 创建Chrome浏览器对象
brower = webdriver.Chrome()

# 定义要访问的URL
url = "https://www.baidu.com"

# 访问URL
brower.get(url)

# 等待3秒
time.sleep(3)

# 找到id为"su"的元素
input = brower.find_element(by=By.ID, value="su")

# 打印元素的class属性
print(input.get_attribute("class"))

# 找到id为"kw"的元素
input = brower.find_element(by=By.ID, value="kw")

# 在元素中输入"周杰伦"
input.send_keys("周杰伦")

time.sleep(3)

# 找到百度一下按钮
button1 = brower.find_element(by=By.ID, value="su")

# 点击该按钮
button1.click()

time.sleep(3)

# 滑到底部
brower.execute_script("window.scrollTo(0, document.body.scrollHeight);")

time.sleep(3)

# 获取下一页的按钮
button2 = brower.find_element(by=By.XPATH, value='//a[@class="n"]')

button2.click()

time.sleep(3)

# 滑到底部
brower.execute_script("window.scrollTo(0, document.body.scrollHeight);")

time.sleep(3)

# 返回上一页
brower.back()

time.sleep(3)

# 回去
brower.forward()

time.sleep(3)

# 关闭浏览器
brower.quit()
